import { defineStore } from 'pinia'
import Api from '@/api'
// import { checkRule } from '@/Utils/human'
import { sessionGet } from '@/Utils/storage'
import { headersStore } from '@/stores/apiHeader'
import { computed } from 'vue'
const month = computed(() => {
  return headersStore().month
})
export const useHumanStore = defineStore('human', {
  persist: {
    enabled: true,
  },
  state: () => {
    return {
      getHumanEffect: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getMetaeffect: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getComparisonHumanEffect: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getComparisonMetaeffect: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getHumanStructure: {
        dimAges: [],
        dimEducations: [],
        dimGenders: [],
        dimNations: [],
        dimPosts: [],
        dimWorkAges: [],
        titles: [],
      },
      getEntryAnalysis: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getDepartureAnalysis: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getEnterComparison: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getDepartureComparison: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getEmployeeTurnoverRate: {
        info: [],
        title: '',
        sub_titles: [],
      },
      // 谷守丙
      getEmployeeNumber: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getLaborCosts: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getLaborCostsContrast: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getPerformance: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getPerformanceContrast: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getComparisonLaborCosts: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getEmployeeLcPYear: {
        info: [],
        title: '',
        sub_titles: [],
      },
      getDepartmentalCostsPie: {
        info: [],
        title: '',
        sub_titles: [],
      },
      gethomepagedata: {
        info: {
          performanceGrade: '',
        },
        title: '',
        sub_titles: [],
      },
      getGlobalPerformanceMonth: {
        title: '',
        tableInfos: [],
      },

      getPerformancedRevenueProfit: {
        info: [],
        title: "",
        sub_titles: []
      },
      getPerformancedRevenueProfitMonth: {
        info: [],
        title: "",
        sub_titles: []
      },
      getDpCategoryCompare: {
        info: [],
        title: "",
        sub_titles: []
      },
      getPerformanceMetrics: {
        info: [],
        title: "",
        sub_titles: []
      },
      getPerformanceMet: {
        info: [],
        title: "",
        sub_titles: []
      },
      getCollectionRate: {
        title: "",
        info: month.value == '00' ? [] : {
          moneyNubem: '',
          amountRatio: ''
        },
        sub_titles: [],

      },

    }
  },

  actions: {
    clearVersion() {
      this.version = {}
    },
    getAll() {
      const humanLevel = sessionGet('role')?.humanLevel || 0
      if (!humanLevel) {
        return ''
      }
      Object.keys(Api.humanApi).forEach((item: any) => {
        // console.log('getAll', item)
        try {
          // 根据字典里规则校验是否调此接口
          // checkRule(item) &&
          Api.humanApi[item]().then((res: any) => {
            if (res.code == 0 || res.code == 10000) {
              if (res.data) {
                this[item] = res.data
              }
            }
          })
        } catch (e) {
          console.log('err', e)
        }
      })
      // // Dict对象获取human的所有key,然后放到一个数组中
      // const keys = Object.keys(Dict.human).filter((item: any) => {
      //   if (!item) {
      //     return false
      //   }
      //   return true
      // })

      // if (keys.length) {
      //   keys.forEach((item: any) => {
      //     try {
      //       Api[item]().then((res: any) => {
      //         if (res.code == 0 || res.code == 10000) {
      //           if (res.data) {
      //             this[item] = res.data
      //           }
      //         }
      //       })
      //     } catch (e) {
      //       console.log('err', e)
      //     }
      //   })
      // }
    },
  },
})
